<?php if(!defined('BASEPATH'))exit('No direct script access allowed');
class untitled extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->library(array('session','account','editor','unicode'));
		$this->load->helper('cookie');
	}
	
	public function index()
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			echo redirect(base_url('untitled/quantri.html'));
		}
		if(isset($_POST['username'])&&($_POST['username']!=NULL)&&isset($_POST['password'])&&($_POST['password']!=NULL))
		{
			$remember = FALSE;
			if(isset($_POST['remember'])&&($_POST['password']==1)) $remember = TRUE;
			$arr = array('username'=>$this->input->post('username'),'password'=>$this->input->post('password'));
			$tmp = $this->account->login($arr, $remember);
			if($tmp==1)
			{
				echo redirect(base_url('untitled/quantri.html'));
			}
			else
			{
				$this->load->view("untitled/index");
			}
		}
		else $this->load->view("untitled/index");
	}
	
	public function logout()
	{
		$this->account->logout();
		echo redirect(base_url());
	}
	
	public function quantri()
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$data1['title'] = 'QUẢN TRỊ WEBSITE';
			$this->load->view('untitled/required/header',$data1);
			$this->load->view('untitled/required/quantri',TRUE);
			$this->load->view('untitled/required/footer',TRUE);
		} else echo redirect(base_url());
	}	public function gioithieu()
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->load->model('gioithieu_model');
			if(isset($_POST['noidung']))
			{
				if($this->gioithieu_model->update($this->input->post('noidung')))
				echo redirect(base_url('untitled/quantri.html'));
				else echo redirect(base_url('untitled/gioithieu.html'));
			}
			else
			{
				$data1['title'] = 'Cập Nhật Giới Thiệu';
				$data2['noidung'] = $this->gioithieu_model->select();
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/gioithieu/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
		} else echo redirect(base_url());
	}
	public function dichvu()
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->load->model('dichvu_model');
			if(isset($_POST['noidung']))
			{
				if($this->dichvu_model->update($this->input->post('noidung')))
				echo redirect(base_url('untitled/quantri.html'));
				else echo redirect(base_url('untitled/dichvu.html'));
			}
			else
			{
				$data1['title'] = 'Cập Nhật Dịch Vụ';
				$data2['noidung'] = $this->dichvu_model->select();
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/dichvu/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
		} else echo redirect(base_url());
	}
	public function tuvan()
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->load->model('tuvan_model');
			if(isset($_POST['noidung']))
			{
				if($this->tuvan_model->update($this->input->post('noidung')))
				echo redirect(base_url('untitled/quantri.html'));
				else echo redirect(base_url('untitled/dichvu.html'));
			}
			else
			{
				$data1['title'] = 'Cập Nhật Dịch Vụ';
				$data2['noidung'] = $this->tuvan_model->select();
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/tuvan/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
		} else echo redirect(base_url());
	}
	public function chungloai($chucnang)
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->load->model('chungloai_model');
			if($chucnang=="xem")
			{
				$data1['title'] = 'Quản Trị Chủng Loại';
				$data2['result'] = $this->chungloai_model->select();
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/chungloai/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
			elseif($chucnang=="them")
			{
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$data1['title'] = 'Thêm Chủng Loại';
					$this->load->view('untitled/required/header',$data1);
					$this->load->view('untitled/chungloai/them',TRUE);
					$this->load->view('untitled/required/footer',TRUE);
				}
				else
				{
					$ten = $this->input->post('ten',TRUE);
					$thutu = $this->input->post('thutu',TRUE);
					$tmp = $this->chungloai_model->insert($ten, $thutu);
					if($tmp>0) echo redirect(base_url('untitled/chungloai/xem.html'));
					else echo redirect(base_url('untitled/loi/them.html'));
				}
			}
			elseif($chucnang=="sua")
			{
				$this->form_validation->set_rules('id','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_rules('anhien','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$id = 0;
					$idg = $this->input->get("id");
					$idp = $this->input->post("id");
					if(is_numeric($idg)) $id = $idg;
					else if(is_numeric($idp)) $id = $idp;
					if($id==0) echo redirect(base_url('untitled/chungloai/xem.html'));
					else
					{
						$data1["title"] = "Cập nhật Chủng Loại";
						$this->load->view("untitled/required/header",$data1);
						$data2['result'] = $this->chungloai_model->edit($id);
						$this->load->view("untitled/chungloai/sua",$data2);
						$this->load->view("untitled/required/footer",TRUE);
					}
				}
				else
				{
					$id = $this->input->post("id",TRUE);
					$ten = $this->input->post("ten",TRUE);
					$thutu = $this->input->post("thutu",TRUE);
					$anhien = $this->input->post("anhien",TRUE);
					$tmp = $this->chungloai_model->update($id, $ten, $thutu, $anhien);
					if($tmp) echo redirect(base_url('untitled/chungloai/xem.html'));
					else echo redirect(base_url('untitled/loi/sua.html'));
				}
			}
			elseif($chucnang=="xoa")
			{
				$id = $this->input->get("id", TRUE);
				if(is_numeric($id)) settype($id,"int");
				else echo redirect(base_url('untitled.html'));
				$tmp = $this->chungloai_model->delete($id);
				if($tmp) echo redirect(base_url('untitled/chungloai/xem.html'));
				else echo redirect(base_url('untitled/loi/xoa.html'));
			}
		} else echo redirect(base_url());
	}
	public function loaiphong($chucnang)
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->load->model('loaiphong_model');
			$this->load->model('chungloai_model');
			if($chucnang=="xem")
			{
				$data1['title'] = 'Quản Trị Loại Phòng';
				$data2['result'] = $this->loaiphong_model->select();
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/loaiphong/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
			elseif($chucnang=="them")
			{
				$this->form_validation->set_rules('idCL','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$data1['title'] = 'Thêm Loại Phòng';
					$this->load->view('untitled/required/header',$data1);
					$data2['resultDDL'] = $this->chungloai_model->getDDL();
					$this->load->view('untitled/loaiphong/them',$data2);
					$this->load->view('untitled/required/footer',TRUE);
				}
				else
				{
					$idCL = $this->input->post('idCL',TRUE);
					$ten = $this->input->post('ten',TRUE);
					$thutu = $this->input->post('thutu',TRUE);
					$tmp = $this->loaiphong_model->insert($idCL, $ten, $thutu);
					if($tmp>0) echo redirect(base_url('untitled/loaiphong/xem.html'));
					else echo redirect(base_url('untitled/loi/them.html'));
				}
			}
			elseif($chucnang=="sua")
			{
				$this->form_validation->set_rules('id','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('idCL','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_rules('anhien','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$id = 0;
					$idg = $this->input->get("id");
					$idp = $this->input->post("id");
					if(is_numeric($idg)) $id = $idg;
					else if(is_numeric($idp)) $id = $idp;
					if($id==0) echo redirect(base_url('untitled/loaiphong/xem.html'));
					else
					{
						$data1["title"] = "Cập nhật Loại Phòng";
						$this->load->view("untitled/required/header",$data1);
						$data2['result'] = $this->loaiphong_model->edit($id);
						$data2['resultDDL'] = $this->chungloai_model->getDDL();
						$this->load->view("untitled/loaiphong/sua",$data2);
						$this->load->view("untitled/required/footer",TRUE);
					}
				}
				else
				{
					$id = $this->input->post("id",TRUE);
					$idCL = $this->input->post('idCL',TRUE);
					$ten = $this->input->post("ten",TRUE);
					$thutu = $this->input->post("thutu",TRUE);
					$anhien = $this->input->post("anhien",TRUE);
					$tmp = $this->loaiphong_model->update($id, $idCL, $ten, $thutu, $anhien);
					if($tmp) echo redirect(base_url('untitled/loaiphong/xem.html'));
					else echo redirect(base_url('untitled/loi/sua.html'));
				}
			}
			elseif($chucnang=="xoa")
			{
				$id = $this->input->get("id", TRUE);
				if(is_numeric($id)) settype($id,"int");
				else echo redirect(base_url('untitled.html'));
				$tmp = $this->loaiphong_model->delete($id);
				if($tmp) echo redirect(base_url('untitled/loaiphong/xem.html'));
				else echo redirect(base_url('untitled/loi/xoa.html'));
			}
		} else echo redirect(base_url());
	}
	public function loai($chucnang)
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->load->model('loaiphong_model');
			$this->load->model('chungloai_model');
			$this->load->model('loai_model');
			if($chucnang=="xem")
			{
				$data1['title'] = 'Quản Trị Loại Sản phẩm';
				$data2['result'] = $this->loai_model->select();
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/loai/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
			elseif($chucnang=="them")
			{
				$this->form_validation->set_rules('idCL','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('idLP','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$data1['title'] = 'Thêm Loại Sản Phẩm';
					$this->load->view('untitled/required/header',$data1);
					$data2['resultDDL'] = $this->chungloai_model->getDDL();
					$this->load->view('untitled/loai/them',$data2);
					$this->load->view('untitled/required/footer',TRUE);
				}
				else
				{
					$idCL = $this->input->post('idCL',TRUE);
					$idLP = $this->input->post('idLP',TRUE);
					$ten = $this->input->post('ten',TRUE);
					$thutu = $this->input->post('thutu',TRUE);
					$tmp = $this->loai_model->insert($idCL, $idLP, $ten, $thutu);
					if($tmp>0) echo redirect(base_url('untitled/loai/xem.html'));
					else echo redirect(base_url('untitled/loi/them.html'));
				}
			}
			elseif($chucnang=="sua")
			{
				$this->form_validation->set_rules('id','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('idCL','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('idLP','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_rules('anhien','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$id = 0;
					$idg = $this->input->get("id");
					$idp = $this->input->post("id");
					if(is_numeric($idg)) $id = $idg;
					else if(is_numeric($idp)) $id = $idp;
					if($id==0) echo redirect(base_url('untitled/loai/xem.html'));
					else
					{
						$data1["title"] = "Cập nhật Loại Sản Phẩm";
						$this->load->view("untitled/required/header",$data1);
						$data2['result'] = $this->loai_model->edit($id);
						$data2['resultDDL'] = $this->chungloai_model->getDDL();
						$this->load->view("untitled/loai/sua",$data2);
						$this->load->view("untitled/required/footer",TRUE);
					}
				}
				else
				{
					$id = $this->input->post("id",TRUE);
					$idCL = $this->input->post('idCL',TRUE);
					$idLP = $this->input->post('idLP',TRUE);
					$ten = $this->input->post("ten",TRUE);
					$thutu = $this->input->post("thutu",TRUE);
					$anhien = $this->input->post("anhien",TRUE);
					$tmp = $this->loai_model->update($id, $idCL, $idLP, $ten, $thutu, $anhien);
					if($tmp) echo redirect(base_url('untitled/loai/xem.html'));
					else echo redirect(base_url('untitled/loi/sua.html'));
				}
			}
			elseif($chucnang=="xoa")
			{
				$id = $this->input->get("id", TRUE);
				if(is_numeric($id)) settype($id,"int");
				else echo redirect(base_url('untitled.html'));
				$tmp = $this->loai_model->delete($id);
				if($tmp) echo redirect(base_url('untitled/loai/xem.html'));
				else echo redirect(base_url('untitled/loi/xoa.html'));
			}
		} else echo redirect(base_url());
	}
	public function sanpham($chucnang)
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->load->library('files');
			$this->load->model('loaiphong_model');
			$this->load->model('chungloai_model');
			$this->load->model('loai_model');
			$this->load->model('sanpham_model');
			if($chucnang=="xem")
			{
				$data1['title'] = 'Quản Trị Sản phẩm';
				$data2['result'] = $this->sanpham_model->select();
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/sanpham/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
			elseif($chucnang=="them")
			{
				$this->form_validation->set_rules('idCL','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('idLP','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('idL','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('gia','','trim|xss_clean');
				$this->form_validation->set_rules('noibat','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('noidung','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$data1['title'] = 'Thêm Sản Phẩm';
					$this->load->view('untitled/required/header',$data1);
					$data2['resultDDL'] = $this->chungloai_model->getDDL();
					$this->load->view('untitled/sanpham/them',$data2);
					$this->load->view('untitled/required/footer',TRUE);
				}
				else
				{
					$idCL = $this->input->post('idCL',TRUE);
					$idLP = $this->input->post('idLP',TRUE);
					$idL = $this->input->post('idL',TRUE);
					$noibat = $this->input->post('noibat',TRUE);
					$ten = $this->input->post('ten',TRUE);
					$gia = $this->input->post('gia',TRUE);
					$noidung = $this->input->post('noidung',TRUE);
					$thutu = $this->input->post('thutu',TRUE);
					$tmp = $this->sanpham_model->insert($idCL, $idLP, $idL, $noibat, $ten, $gia, $noidung, $thutu);
					if($tmp>0) echo redirect(base_url('untitled/sanpham/sua.html?id='.$tmp));
					else echo redirect(base_url('untitled/loi/them.html'));
				}
			}
			elseif($chucnang=="sua")
			{
				$this->form_validation->set_rules('id','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('idCL','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('idLP','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('idL','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('gia','','trim|xss_clean');
				$this->form_validation->set_rules('noibat','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('noidung','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_rules('anhien','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$id = 0;
					$idg = $this->input->get("id");
					$idp = $this->input->post("id");
					if(is_numeric($idg)) $id = $idg;
					else if(is_numeric($idp)) $id = $idp;
					if($id==0) echo redirect(base_url('untitled/sanpham/xem.html'));
					else
					{
						$data1["title"] = "Cập nhật Sản Phẩm";
						$this->load->view("untitled/required/header",$data1);
						$data2['result'] = $this->sanpham_model->edit($id);
						$data2['resultDDL'] = $this->chungloai_model->getDDL();
						$this->load->view("untitled/sanpham/sua",$data2);
						$this->load->view("untitled/required/footer",TRUE);
					}
				}
				else
				{
					$id = $this->input->post("id",TRUE);
					$idCL = $this->input->post('idCL',TRUE);
					$idLP = $this->input->post('idLP',TRUE);
					$idL = $this->input->post('idL',TRUE);
					$noibat = $this->input->post('noibat',TRUE);
					$ten = $this->input->post('ten',TRUE);
					$gia = $this->input->post('gia',TRUE);
					$noidung = $this->input->post('noidung',TRUE);
					$thutu = $this->input->post("thutu",TRUE);
					$anhien = $this->input->post("anhien",TRUE);
					$tmp = $this->sanpham_model->update($id, $idCL, $idLP, $idL, $noibat, $ten, $gia, $noidung, $thutu, $anhien);
					if($tmp) echo redirect(base_url('untitled/sanpham/xem.html'));
					else echo redirect(base_url('untitled/loi/sua.html'));
				}
			}
			elseif($chucnang=="xoa")
			{
				$id = $this->input->get("id", TRUE);
				if(is_numeric($id)) settype($id,"int");
				else echo redirect(base_url('untitled.html'));
				$tmp = $this->sanpham_model->delete($id);
				if($tmp) echo redirect(base_url('untitled/sanpham/xem.html'));
				else echo redirect(base_url('untitled/loi/xoa.html'));
			}
		} else echo redirect(base_url());
	}
	public function loaitin($chucnang)
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->load->model('loaitin_model');
			if($chucnang=="xem")
			{
				$data1['title'] = 'Quản Trị Loại Tin';
				$data2['result'] = $this->loaitin_model->select();
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/loaitin/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
			elseif($chucnang=="them")
			{
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$data1['title'] = 'Thêm Loại Tin';
					$this->load->view('untitled/required/header',$data1);
					$this->load->view('untitled/loaitin/them',TRUE);
					$this->load->view('untitled/required/footer',TRUE);
				}
				else
				{
					$ten = $this->input->post('ten',TRUE);
					$thutu = $this->input->post('thutu',TRUE);
					$tmp = $this->loaitin_model->insert($ten, $thutu);
					if($tmp>0) echo redirect(base_url('untitled/loaitin/xem.html'));
					else echo redirect(base_url('untitled/loi/them.html'));
				}
			}
			elseif($chucnang=="sua")
			{
				$this->form_validation->set_rules('id','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_rules('anhien','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$id = 0;
					$idg = $this->input->get("id");
					$idp = $this->input->post("id");
					if(is_numeric($idg)) $id = $idg;
					else if(is_numeric($idp)) $id = $idp;
					if($id==0) echo redirect(base_url('untitled/loaitin/xem.html'));
					else
					{
						$data1["title"] = "Cập nhật Loại Tin";
						$this->load->view("untitled/required/header",$data1);
						$data2['result'] = $this->loaitin_model->edit($id);
						$this->load->view("untitled/loaitin/sua",$data2);
						$this->load->view("untitled/required/footer",TRUE);
					}
				}
				else
				{
					$id = $this->input->post("id",TRUE);
					$ten = $this->input->post("ten",TRUE);
					$thutu = $this->input->post("thutu",TRUE);
					$anhien = $this->input->post("anhien",TRUE);
					$tmp = $this->loaitin_model->update($id, $ten, $thutu, $anhien);
					if($tmp) echo redirect(base_url('untitled/loaitin/xem.html'));
					else echo redirect(base_url('untitled/loi/sua.html'));
				}
			}
			elseif($chucnang=="xoa")
			{
				$id = $this->input->get("id", TRUE);
				if(is_numeric($id)) settype($id,"int");
				else echo redirect(base_url('untitled.html'));
				$tmp = $this->loaitin_model->delete($id);
				if($tmp) echo redirect(base_url('untitled/loaitin/xem.html'));
				else echo redirect(base_url('untitled/loi/xoa.html'));
			}
		} else echo redirect(base_url());
	}
	public function tin($chucnang)
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->load->model('tin_model');
			$this->load->model('loaitin_model');
			if($chucnang=="xem")
			{
				$data1['title'] = 'Quản Trị Tin';
				$data2['result'] = $this->tin_model->select();
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/tin/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
			elseif($chucnang=="them")
			{
				$this->form_validation->set_rules('idLT','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('tomtat','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('noidung','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$data1['title'] = 'Thêm Tin';
					$this->load->view('untitled/required/header',$data1);
					$data2['resultDDL'] = $this->loaitin_model->getDDL();
					$this->load->view('untitled/tin/them',$data2);
					$this->load->view('untitled/required/footer',TRUE);
				}
				else
				{
					$idLT = $this->input->post('idLT',TRUE);
					$ten = $this->input->post('ten',TRUE);
					$tomtat = $this->input->post('tomtat',TRUE);
					$noidung = $this->input->post('noidung',TRUE);
					$thutu = $this->input->post('thutu',TRUE);
					$tmp = $this->tin_model->insert($idLT, $ten, $tomtat, $noidung, $thutu);
					if($tmp>0) echo redirect(base_url('untitled/tin/xem.html'));
					else echo redirect(base_url('untitled/loi/them.html'));
				}
			}
			elseif($chucnang=="sua")
			{
				$this->load->library('files');
				$this->form_validation->set_rules('id','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('idLT','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('tomtat','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('noidung','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_rules('anhien','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$id = 0;
					$idg = $this->input->get("id");
					$idp = $this->input->post("id");
					if(is_numeric($idg)) $id = $idg;
					else if(is_numeric($idp)) $id = $idp;
					if($id==0) echo redirect(base_url('untitled/loaitin/xem.html'));
					else
					{
						$data1["title"] = "Cập nhật Tin";
						$this->load->view("untitled/required/header",$data1);
						$data2['result'] = $this->tin_model->edit($id);
						$data2['resultDDL'] = $this->loaitin_model->getDDL();
						$this->load->view("untitled/tin/sua",$data2);
						$this->load->view("untitled/required/footer",TRUE);
					}
				}
				else
				{
					$id = $this->input->post("id",TRUE);
					$idLT = $this->input->post("idLT",TRUE);
					$ten = $this->input->post("ten",TRUE);
					$tomtat = $this->input->post("tomtat",TRUE);
					$noidung = $this->input->post("noidung",TRUE);
					$thutu = $this->input->post("thutu",TRUE);
					$anhien = $this->input->post("anhien",TRUE);
					$tmp = $this->tin_model->update($id, $idLT, $ten, $tomtat, $noidung, $thutu, $anhien);
					if($tmp) echo redirect(base_url('untitled/tin/xem.html'));
					else echo redirect(base_url('untitled/loi/sua.html'));
				}
			}
			elseif($chucnang=="xoa")
			{
				$id = $this->input->get("id", TRUE);
				if(is_numeric($id)) settype($id,"int");
				else echo redirect(base_url('untitled.html'));
				$tmp = $this->tin_model->delete($id);
				if($tmp) echo redirect(base_url('untitled/tin/xem.html'));
				else echo redirect(base_url('untitled/loi/xoa.html'));
			}
		} else echo redirect(base_url());
	}
	public function lienhe($chucnang)
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->load->model('lienhe_model');
			if($chucnang=="xem")
			{
				$data1['title'] = 'Quản Trị Liên Hệ';
				$data2['result'] = $this->lienhe_model->select();
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/lienhe/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
			elseif($chucnang=="xoa")
			{
				$id = $this->input->get("id", TRUE);
				if(is_numeric($id)) settype($id,"int");
				else echo redirect(base_url('untitled.html'));
				$tmp = $this->lienhe_model->delete($id);
				if($tmp) echo redirect(base_url('untitled/lienhe/xem.html'));
				else echo redirect(base_url('untitled/loi/xoa.html'));
			}
		} else echo redirect(base_url());
	}
	public function hotro($chucnang)
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->load->model('hotro_model');
			if($chucnang=="xem")
			{
				$data1['title'] = 'Quản Trị Hỗ Trợ';
				$data2['result'] = $this->hotro_model->select();
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/hotro/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
			elseif($chucnang=="sua")
			{
				$this->form_validation->set_rules('id','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_rules('ten','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('phone','','trim|required|min_length[2]|xss_clean');
				$this->form_validation->set_rules('thutu','','trim|xss_clean');
				$this->form_validation->set_rules('anhien','','trim|required|alpha_numeric|xss_clean');
				$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
				if ($this->form_validation->run() == FALSE)
				{
					$id = 0;
					$idg = $this->input->get("id");
					$idp = $this->input->post("id");
					if(is_numeric($idg)) $id = $idg;
					else if(is_numeric($idp)) $id = $idp;
					if($id==0) echo redirect(base_url('untitled/hotro/xem.html'));
					else
					{
						$data1["title"] = "Cập nhật Hỗ Trợ";
						$this->load->view("untitled/required/header",$data1);
						$data2['result'] = $this->hotro_model->edit($id);
						$this->load->view("untitled/hotro/sua",$data2);
						$this->load->view("untitled/required/footer",TRUE);
					}
				}
				else
				{
					$id = $this->input->post("id",TRUE);
					$ten = $this->input->post("ten",TRUE);
					$phone = $this->input->post("phone",TRUE);
					$thutu = $this->input->post("thutu",TRUE);
					$anhien = $this->input->post("anhien",TRUE);
					$tmp = $this->hotro_model->update($id, $ten, $phone, $thutu, $anhien);
					if($tmp) echo redirect(base_url('untitled/hotro/xem.html'));
					else echo redirect(base_url('untitled/loi/sua.html'));
				}
			} else echo redirect(base_url());
		} else echo redirect(base_url());
	}
	public function upload()
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{//file_name
			if(isset($_POST['folder'])&&isset($_POST['loai'])&&isset($_POST['id'])&&isset($_POST['url'])&&isset($_POST['hinh']))
			{
				//linksanpham: base_url('untitled/upload.html?folder=upload/sanpham/$item->id&loai=1&id=$item->id')
				//linktin: base_url('untitled/upload.html?folder=upload/tin/&loai=0&id=$item->id')
				$folder = $this->input->post('folder',TRUE);//sanpham: upload/sanpham/1 tintuc: upload/tintuc/
				$loai = $this->input->post('loai',TRUE);//1:sanpham; 0:tin
				$id = $this->input->post('id',TRUE);
				$url = $this->input->post('url',TRUE);
				$hinh = $this->input->post('hinh',TRUE);
				$config['upload_path'] = './'.$folder.'/';//'./upload/';
				$config['allowed_types'] = 'gif|jpg|png|jpeg';
				$config['max_size']	= '150';
				$config['max_width'] = '1280';
				$config['max_height'] = '1280';
				$this->load->library('upload', $config);
				if(is_numeric($id)&&is_numeric($hinh)&&is_numeric($loai)&&($folder!=NULL)&&($url!=NULL))
				{
					if (!$this->upload->do_upload())
					{
						echo redirect($url);
					}
					else
					{
						$arr = $this->upload->data();
						$filename = $arr['file_name'];
						settype($loai,'int');settype($hinh,'int');
						if($loai==1)
						{
							$this->load->model('sanpham_model');
							$tmp = $this->sanpham_model->image($id,$filename,$hinh);
							if($tmp) echo redirect($url);
							else echo redirect(base_url('untitled/loi/sua.html'));
						}
						elseif($loai==2)
						{
							$this->load->model('tin_model');
							$tmp = $this->tin_model->image($id,$filename);
							if($tmp) echo redirect($url);
							else echo redirect(base_url('untitled/loi/sua.html'));
						}
					}
				}
				echo redirect(base_url('untitled/loi/upload.html'));
			}
			$data1["title"] = "Tải Ảnh";
			$this->load->view('untitled/required/header',$data1);
			$data2['error'] = '';
			$this->load->view('untitled/upload/index',$data2);
			$this->load->view('untitled/required/footer',TRUE);
			//$this->output->enable_profiler(TRUE);
		} else echo redirect(base_url());
	}
	public function changepassword()
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$this->form_validation->set_rules('password','','trim|required|min_length[5]|xss_clean');
			$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
			if ($this->form_validation->run() == FALSE)
			{
				$data1["title"] = "Đổi Mật Khẩu";
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/account/password',TRUE);
				$this->load->view('untitled/required/footer',TRUE);
			}
			else
			{
				if($chk==1) $arr['username'] = $this->session->userdata('un',TRUE);
				else $arr['username'] = $this->input->cookie('un',TRUE);
				$arr['password'] = $this->input->post("password",TRUE);
				$tmp = $this->account->changepassword($arr);
				if($tmp==1) echo redirect(base_url('untitled.html'));
				else echo $tmp;
			}
		} else echo redirect(base_url());
	}
	public function accounts()
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			if($chk==1) $arr['role'] = $this->session->userdata('rl',TRUE);
			else $arr['role'] = $this->input->cookie('rl',TRUE);
			if($arr['role']==77)
			{
				$data2['result'] = $this->account->getaccountbyrole(99);
				$data1["title"] = "Quản Trị Tài Khoản";
				$this->load->view('untitled/required/header',$data1);
				$this->load->view('untitled/account/index',$data2);
				$this->load->view('untitled/required/footer',TRUE);
			}
			else echo redirect(base_url());
		} else echo redirect(base_url());
	}
	public function changestatus()
	{
		$chk = $this->account->checkLogin();
		if(($chk==1)||$chk==2)
		{
			$arr['username'] = $this->input->get('username',TRUE);
			$arr['role'] = $this->input->get('status',TRUE); settype($arr['role'],'int');
			if($this->account->checkUsername($arr))
			{
				if($arr['role']==99)
				{
					$arr['role']=1;
					$tmp = $this->account->updateRole($arr);
				}
				elseif($arr['role']==1)
				{
					$arr['role']=99;
					$tmp = $this->account->updateRole($arr);
				}
				else echo redirect(base_url('untitled/loi/sua.html'));
				if($tmp==1) echo redirect(base_url('untitled/accounts.html'));
				else echo redirect(base_url('untitled/loi/sua.html'));
			}
		} else echo redirect(base_url());
	}
	public function getDDL($loaiid,$loai,$id,$values)
	{
		if($loaiid=="idCL")
		{
			$this->load->model('loaiphong_model');
			$data['result'] = $this->loaiphong_model->getDDL($id);
			if($loai=="insert") $this->load->view("DDLinsert",$data);
			else
			{
				$data['values'] = $values;
				$this->load->view("DDLupdate",$data);
			}
		}
		if($loaiid=="idLP")
		{
			$this->load->model('loai_model');
			$data['result'] = $this->loai_model->getDDL($loai,$id);
			if($values=="0") $this->load->view("DDLinsert",$data);
			else
			{
				$data['values'] = $values;
				$this->load->view("DDLupdate",$data);
			}
		}
	}
	public function xoahinh()
	{
		$url = $this->input->get('url',TRUE);
		$id = $this->input->get('id',TRUE);
		$loai = $this->input->get('loai',TRUE);
		if($loai=='sanpham')
		{
			$thutu = $this->input->get('thutu',TRUE);
			if(is_numeric($id)&&is_numeric($thutu))
			{
				$this->load->model('sanpham_model');
				$this->sanpham_model->deleteImage($id,$thutu);
			}
		}
		elseif($loai=='tin')
		{
			if(is_numeric($id))
			{
				$this->load->model('tin_model');
				$this->tin_model->deleteImage($id);
			}
		}
		echo redirect($url);
	}
}